package system;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import connect.connect;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.JInternalFrame;
import javax.swing.border.LineBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import connect.connect;
import java.sql.*;
import java.util.Calendar;
import java.util.Vector;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.io.IOException;

import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.ScrollPane;

import javax.swing.JFormattedTextField;
import javax.swing.JTable;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.text.*;
import system.Table;
import system.Login;
import system.MainFrame;

public class PutInStorage {
 
	  public static Integer State;
	
	  //���״̬
	@SuppressWarnings("finally")
	public static Integer getState(String value){
		State=2;
		try {
			String sql = "select * from PutInStorage where pi_id ="+value+"";
//			System.out.println(sql+"++++++++++++++");
			Connection conn = connect.getConnection();
			Statement stat = conn.createStatement();
			ResultSet rs = stat.executeQuery(sql);
			while (rs.next()) { // ����ȡ�����
//				JOptionPane.showMessageDialog(null, "+++++++"); //����
				State=rs.getInt(12);
//				JOptionPane.showMessageDialog(null, State); //����
			}
			stat.close();
			conn.close();
		} catch (SQLException sqlex) {
			sqlex.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}finally{
			return State;
		}
	}
	 
	//ǰһ��
	 public static void DrawPanel_m1(JTextField pi_id,JFormattedTextField pi_time,JComboBox department,JComboBox yewuyuan,JComboBox supplier,JComboBox warehouse,JTextArea memo,JFormattedTextField zhidanren,JFormattedTextField zd_time,JFormattedTextField shenheren,JFormattedTextField sh_time){
			pi_time.setText("");
			department.removeAllItems();
			yewuyuan.removeAllItems();
			supplier.removeAllItems();
			warehouse.removeAllItems();
			memo.setText("");
			zhidanren.setText("");
			zd_time.setText("");
			shenheren.setText("");
			sh_time.setText("");

			int a = Integer.parseInt(pi_id.getText());
			a = a - 1;
			if (a <= 1) {
				a = 1;
			}
			String b = String.valueOf(a);
			pi_id.setText(b);

			try {
				int r0 = 0;
				int r5 = 0;

				String sql0 = "select  * from PutInStorage where pi_id='"
						+ pi_id.getText() + "'";

				Connection conn = connect.getConnection();
				Statement stat = conn.createStatement();

				ResultSet rs0 = stat.executeQuery(sql0);

				while (rs0.next()) { // ����ȡ�����

					String a3 = rs0.getDate(2).toString();
					pi_time.setText((a3 == null || a3 == "") ? "" : a3);
					department.addItem(rs0.getString(3));
					yewuyuan.removeAllItems();
					yewuyuan.addItem(rs0.getString(4));
					supplier.addItem(rs0.getString(5));
					warehouse.addItem(rs0.getString(6));
					memo.setText(rs0.getString(7));
					zhidanren.setText(rs0.getString(8));
					String a1 = rs0.getDate(9).toString();
					zd_time.setText(a1);

					String a11 = rs0.getString(10);
					shenheren
							.setText((a11 == null || a11 == "") ? "" : a11);
					Date a2 = rs0.getDate(11);
					sh_time.setText((a2 == null) ? "" : a2.toString());

				}

				stat.close();
				conn.close();
			} catch (SQLException sqlex) {
				sqlex.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			

		 
		 
	 }
	 
	 //��һ��
	 public static void DrawPanel_p1(JTextField pi_id,JFormattedTextField pi_time,JComboBox department,JComboBox yewuyuan,JComboBox supplier,JComboBox warehouse,JTextArea memo,JFormattedTextField zhidanren,JFormattedTextField zd_time,JFormattedTextField shenheren,JFormattedTextField sh_time){
		 pi_time.setText("");
			department.removeAllItems();
			yewuyuan.removeAllItems();
			supplier.removeAllItems();
			warehouse.removeAllItems();
			memo.setText("");
			zhidanren.setText("");
			zd_time.setText("");
			shenheren.setText("");
			sh_time.setText("");
			int a1 = 0;
			try {
				String sql = "select max(pi_id) from PutInStorage";
				Connection conn = connect.getConnection();
				Statement stat = conn.createStatement();

				ResultSet rs = stat.executeQuery(sql);
				while (rs.next()) { // ����ȡ�����
					// JOptionPane.showMessageDialog(null, "+++++++"); //����
					a1 = rs.getInt(1);
					// System.out.println(a1);

				}

				stat.close();
				conn.close();
			} catch (SQLException sqlex) {
				sqlex.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}

			int a = Integer.parseInt(pi_id.getText());
			a = a + 1;
			if (a >= a1) {
				a = a1;
			}
			String b = String.valueOf(a);
			pi_id.setText(b);

			try {
				int r0 = 0;
				int r5 = 0;

				String sql0 = "select  * from PutInStorage where pi_id='"
						+ pi_id.getText() + "'";

				Connection conn = connect.getConnection();
				Statement stat = conn.createStatement();

				ResultSet rs0 = stat.executeQuery(sql0);

				while (rs0.next()) { // ����ȡ�����

					String a3 = rs0.getDate(2).toString();
					pi_time.setText((a3 == null || a3 == "") ? "" : a3);
					department.addItem(rs0.getString(3));
					yewuyuan.removeAllItems();
					yewuyuan.addItem(rs0.getString(4));
					supplier.addItem(rs0.getString(5));
					warehouse.addItem(rs0.getString(6));
					memo.setText(rs0.getString(7));
					zhidanren.setText(rs0.getString(8));
					String a11 = rs0.getDate(9).toString();
					zd_time.setText(a11);

					String a111 = rs0.getString(10);
					shenheren.setText((a111 == null || a111 == "") ? "": a111);

					Date a2 = rs0.getDate(11);
					sh_time.setText((a2 == null) ? "" : a2.toString());
				}

				// JOptionPane.showMessageDialog(null, pi_id.getText());
				// //����

				stat.close();
				conn.close();
			} catch (SQLException sqlex) {
				sqlex.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			

		 
		 
	 }
	  
	 private static final long serialVersionUID = 1L;
		private JPanel contentPane;
		private JTextField cu_name;
		private JTextField cu_phone;
		private JTextField address;
		private JTextField l_degree;
		private JTextField g_degree;
		private JTextField gd_shortname;
		private JTextField gd_name;
		private JTextField gd_pycode;
		private JTextField gd_property;
		private JTextField gd_specification;
		private JTextField gd_proplace;
		private JTextField gd_unit;
		private JTextField gd_type;
		private JTextField gd_serial;
		private JTextField gd_batch;
		private JTextField gd_price;
		private JTextField gd_supplier;
		private JTextField gd_pesticidereg;
		private JTextField gd_pesticidepro;
		private JTextField gd_safetylevel;
		private JTextField gd_barcode;
		private static JTextField pi_id;
		private static JTextField gd_name1;
		private static JTextField gd_type1;
		private static JTextField gd_unit1;
		private static JTextField amount;
		private static JTextField unitprice;
		private static JTextField tax;
		private static JTextField taxprice;
		private static JTextField total;
		private static JTable table;
		private JFormattedTextField pi_time;
		private JComboBox department;
		private JComboBox yewuyuan;
		private JComboBox supplier;
		private JComboBox warehouse;
		private JTextArea memo;
		private JFormattedTextField zhidanren;
		private JFormattedTextField zd_time;
		private JFormattedTextField shenheren;
		private JFormattedTextField sh_time;
		private JLabel label_62;

		/**
		 * @param args
		 */
		public static void addPutInStorage(JTabbedPane tabbedPane) {
			// TODO Auto-generated method stub

			final JPanel panel_1 = new JPanel();
			
			final JLabel label_62 = new JLabel("\u672A\u5BA1\u6838");
			label_62.setHorizontalAlignment(SwingConstants.CENTER);
			label_62.setForeground(Color.RED);
			label_62.setFont(new Font("΢���ź�", Font.BOLD, 20));
			label_62.setBounds(786, 300, 60, 30);
			panel_1.add(label_62);
			
			table = new JTable();

			pi_id = new JTextField();
			pi_id.setEditable(false);
			pi_id.setBounds(263, 131, 90, 21);
			panel_1.add(pi_id);
			pi_id.setColumns(10);

			final JComboBox department = new JComboBox();

			JLabel label_36 = new JLabel("\u5165\u5E93\u65E5\u671F\uFF1A");
			label_36.setHorizontalAlignment(SwingConstants.RIGHT);
			label_36.setBounds(406, 134, 68, 15);
			panel_1.add(label_36);

			final JFormattedTextField pi_time = new JFormattedTextField();
			pi_time.setHorizontalAlignment(SwingConstants.LEFT);
			pi_time.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					DateChooser mDateChooser = new DateChooser(pi_time);
					// ����DateChooser����λ��
					Point p = pi_time.getLocationOnScreen();
					p.y = p.y + 30;
					mDateChooser.showDateChooser(p);
					pi_time.requestFocusInWindow();
				}
			});
			pi_time.setBounds(484, 131, 90, 21);
			panel_1.add(pi_time);

			JLabel label_37 = new JLabel("\u90E8\u95E8\uFF1A");
			label_37.setHorizontalAlignment(SwingConstants.RIGHT);
			label_37.setBounds(618, 134, 44, 15);
			panel_1.add(label_37);

			JLabel label_38 = new JLabel("\u4E1A\u52A1\u5458\uFF1A");
			label_38.setHorizontalAlignment(SwingConstants.CENTER);
			label_38.setBounds(199, 172, 54, 15);
			panel_1.add(label_38);

			final JComboBox yewuyuan = new JComboBox();
			yewuyuan.setBounds(263, 169, 90, 21);
			panel_1.add(yewuyuan);

			final JComboBox supplier = new JComboBox();
			supplier.setBounds(484, 166, 90, 21);
			panel_1.add(supplier);

			JLabel label_39 = new JLabel("\u4F9B\u5E94\u5546\uFF1A");
			label_39.setHorizontalAlignment(SwingConstants.CENTER);
			label_39.setBounds(423, 169, 54, 15);
			panel_1.add(label_39);

			final JComboBox warehouse = new JComboBox();
			warehouse.setBounds(672, 166, 90, 21);
			panel_1.add(warehouse);

			JLabel label_40 = new JLabel("\u4ED3\u5E93\uFF1A");
			label_40.setHorizontalAlignment(SwingConstants.RIGHT);
			label_40.setBounds(618, 169, 44, 15);
			panel_1.add(label_40);

			JLabel label_41 = new JLabel("\u5907\u6CE8\uFF1A");
			label_41.setHorizontalAlignment(SwingConstants.RIGHT);
			label_41.setBounds(187, 229, 54, 15);
			panel_1.add(label_41);

			final JTextArea memo = new JTextArea();
			memo.setBounds(261, 225, 501, 65);
			panel_1.add(memo);

			JLabel label_42 = new JLabel("\u5236\u5355\u4EBA\uFF1A");
			label_42.setHorizontalAlignment(SwingConstants.CENTER);
			label_42.setBounds(202, 309, 54, 15);
			panel_1.add(label_42);

			final JFormattedTextField zd_time = new JFormattedTextField();
			zd_time.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {

					DateChooser mDateChooser = new DateChooser(zd_time);
					// ����DateChooser����λ��
					Point p = zd_time.getLocationOnScreen();
					p.y = p.y + 30;
					mDateChooser.showDateChooser(p);
					zd_time.requestFocusInWindow();

				}
			});
			
					final JFormattedTextField zhidanren = new JFormattedTextField();
					zhidanren.setEditable(false);
					zhidanren.setBounds(263, 306, 60, 21);
					panel_1.add(zhidanren);
			
					JLabel label_43 = new JLabel("\u5236\u5355\u65E5\u671F\uFF1A");
					label_43.setHorizontalAlignment(SwingConstants.RIGHT);
					label_43.setBounds(328, 309, 68, 15);
					panel_1.add(label_43);
			zd_time.setBounds(394, 306, 80, 21);
			panel_1.add(zd_time);

			JLabel label_45 = new JLabel("\u5BA1\u6838\u65E5\u671F\uFF1A");
			label_45.setHorizontalAlignment(SwingConstants.RIGHT);
			label_45.setBounds(604, 309, 68, 15);
			panel_1.add(label_45);

			final JFormattedTextField sh_time = new JFormattedTextField();
			sh_time.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {

					DateChooser mDateChooser = new DateChooser(sh_time);
					// ����DateChooser����λ��
					Point p = sh_time.getLocationOnScreen();
					p.y = p.y + 30;
					mDateChooser.showDateChooser(p);
					sh_time.requestFocusInWindow();

				}
			});
					
							JLabel label_44 = new JLabel("\u5BA1\u6838\u4EBA\uFF1A");
							label_44.setHorizontalAlignment(SwingConstants.CENTER);
							label_44.setBounds(484, 309, 54, 15);
							panel_1.add(label_44);
			
					final JFormattedTextField shenheren = new JFormattedTextField();
					shenheren.setEditable(false);
					shenheren.setBounds(544, 306, 60, 21);
					panel_1.add(shenheren);
			sh_time.setBounds(682, 306, 80, 21);
			panel_1.add(sh_time);

			
			
			final JLabel label_57 = new JLabel("\u5220\u9664");
			label_57.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(PutInStorage.getState(pi_id.getText())==1){JOptionPane.showMessageDialog(panel_1, "�Բ��𣬸���ⵥ�Ѿ���ˣ�����ɾ��");return;}
//					System.out.println(shenheren.getText() + "+++++++");
					if (shenheren.getText().trim().equals(null)|| shenheren.getText().trim().equals("")) {

						int res = JOptionPane.showConfirmDialog(panel_1, "ȷ��Ҫɾ����",
								"��ʾ", JOptionPane.YES_NO_CANCEL_OPTION);
						if (res == JOptionPane.YES_OPTION) {
							try {
								String sql = "delete from PutInStorageDetail where PutInStorageDetail.pi_id='"
										+ pi_id.getText()
										+ "'"
										+ "delete from PutInStorage where PutInStorage.pi_id='"
										+ pi_id.getText() + "'";
								Connection conn = connect.getConnection();
								Statement stat = conn.createStatement();
								int rs = stat.executeUpdate(sql);
								if (rs == 0) {
									
									PutInStorage.DrawPanel_p1(pi_id, pi_time, department, yewuyuan, supplier, warehouse, memo, zhidanren, zd_time, shenheren, sh_time);
									if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
									else{label_62.setText("δ���");}
									label_62.setVisible(true);
									Table.DrawTable(pi_id.getText(), panel_1, table);
									JOptionPane
											.showMessageDialog(panel_1, " ɾ��ɹ���");
								}
								stat.close();
								conn.close();
							} catch (SQLException sqlex) {
								sqlex.printStackTrace();
							} catch (IOException e) {
								e.printStackTrace();
							}
						}
					}
					else{
						JOptionPane.showMessageDialog(panel_1,
								" �Բ��𣬸���ⵥ�Ѿ���ˣ�����ɾ��");
						return;
					}

					
				}
			});
			
			
			
			
			label_57.setFont(new Font("΢���ź�", Font.PLAIN, 15));
			label_57.setHorizontalAlignment(SwingConstants.CENTER);
			label_57.setForeground(new Color(0, 0, 205));
			label_57.setBounds(562, 0, 60, 30);
			panel_1.add(label_57);

			JLabel label_46 = new JLabel("\u7269\u54C1\u7F16\u53F7");
			label_46.setHorizontalAlignment(SwingConstants.CENTER);
			label_46.setBounds(145, 350, 54, 15);
			panel_1.add(label_46);

			JLabel label_47 = new JLabel("\u7269\u54C1\u540D\u79F0");
			label_47.setHorizontalAlignment(SwingConstants.CENTER);
			label_47.setBounds(226, 350, 54, 15);
			panel_1.add(label_47);

			JLabel label_48 = new JLabel("\u89C4\u683C\u578B\u53F7");
			label_48.setHorizontalAlignment(SwingConstants.CENTER);
			label_48.setBounds(296, 350, 54, 15);
			panel_1.add(label_48);

			JLabel label_49 = new JLabel("\u8BA1\u91CF\u5355\u4F4D");
			label_49.setHorizontalAlignment(SwingConstants.CENTER);
			label_49.setBounds(366, 350, 54, 15);
			panel_1.add(label_49);

			JLabel label_50 = new JLabel("\u6570\u91CF");
			label_50.setHorizontalAlignment(SwingConstants.CENTER);
			label_50.setBounds(436, 350, 54, 15);
			panel_1.add(label_50);

			JLabel label_51 = new JLabel("\u5355\u4EF7");
			label_51.setHorizontalAlignment(SwingConstants.CENTER);
			label_51.setBounds(506, 350, 54, 15);
			panel_1.add(label_51);

			JLabel label_52 = new JLabel("\u7A0E\u7387(%)");
			label_52.setHorizontalAlignment(SwingConstants.CENTER);
			label_52.setBounds(576, 350, 54, 15);
			panel_1.add(label_52);

			JLabel label_53 = new JLabel("\u542B\u7A0E\u5355\u4EF7");
			label_53.setHorizontalAlignment(SwingConstants.CENTER);
			label_53.setBounds(646, 350, 54, 15);
			panel_1.add(label_53);

			JLabel label_54 = new JLabel("\u5408\u8BA1");
			label_54.setHorizontalAlignment(SwingConstants.CENTER);
			label_54.setBounds(716, 350, 54, 15);
			panel_1.add(label_54);

			JLabel label_32 = new JLabel("\u5165\u5E93\u5355");
			label_32.setHorizontalAlignment(SwingConstants.CENTER);
			label_32.setFont(new Font("΢���ź�", Font.PLAIN, 20));
			label_32.setBounds(406, 71, 152, 36);
			panel_1.add(label_32);

			final JLabel label_33 = new JLabel("\u524D\u4E00\u5355");
			label_33.setFont(new Font("΢���ź�", Font.PLAIN, 15));
			label_33.setForeground(new Color(0, 0, 205));
			label_33.addMouseListener(new MouseAdapter() {
				@SuppressWarnings({ "unchecked", "unused" })
				@Override
				public void mouseClicked(MouseEvent arg0) {
					PutInStorage.DrawPanel_m1(pi_id, pi_time, department, yewuyuan, supplier, warehouse, memo, zhidanren, zd_time, shenheren, sh_time);
					
					if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
					else{label_62.setText("δ���");}
					label_62.setVisible(true);
					Table.DrawTable(pi_id.getText(), panel_1, table);
					
					
				}
			});
			label_33.setHorizontalAlignment(SwingConstants.CENTER);
			label_33.setBounds(257, 0, 60, 30);
			panel_1.add(label_33);

			final JLabel label_34 = new JLabel("\u540E\u4E00\u5355");
			label_34.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					PutInStorage.DrawPanel_p1(pi_id, pi_time, department, yewuyuan, supplier, warehouse, memo, zhidanren, zd_time, shenheren, sh_time);
					
					if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
					else{label_62.setText("δ���");}
					label_62.setVisible(true);
					Table.DrawTable(pi_id.getText(), panel_1, table);
					
				}

			});
			label_34.setFont(new Font("΢���ź�", Font.PLAIN, 15));
			label_34.setForeground(new Color(0, 0, 205));
			label_34.setHorizontalAlignment(SwingConstants.CENTER);
			label_34.setBounds(333, 0, 60, 30);
			panel_1.add(label_34);

			JLabel label_35 = new JLabel("\u5165\u5E93\u5355\u7F16\u53F7\uFF1A");
			label_35.setHorizontalAlignment(SwingConstants.RIGHT);
			label_35.setBounds(165, 134, 89, 15);
			panel_1.add(label_35);

			final JComboBox gd_id1 = new JComboBox();
			gd_id1.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent e) {
					if (gd_id1.getSelectedItem() == ""
							|| gd_id1.getSelectedItem() == null) {
						return;
					}

					try {
						String sql = "select * from Good where gd_id='"
								+ gd_id1.getSelectedItem() + "'";
						Connection conn = connect.getConnection();
						Statement stat = conn.createStatement();

						ResultSet rs = stat.executeQuery(sql);
						while (rs.next()) { // ����ȡ�����
							// JOptionPane.showMessageDialog(null, "+++++++"); //����
							gd_name1.setText(rs.getString(2));
							gd_type1.setText(rs.getString(7));
							gd_unit1.setText(rs.getString(9));
							unitprice.setText(rs.getString(14));

						}

						stat.close();
						conn.close();
					} catch (SQLException sqlex) {
						sqlex.printStackTrace();
					} catch (IOException e1) {
						e1.printStackTrace();
					}

					float a, a1;
					String tem = unitprice.getText();
					a = 1
							+ Float.parseFloat(tem.equals("") ? "0" : tem)
							* (Float.parseFloat(tax.getText().equals("") ? "17"
									: tax.getText())) / 100;
					String tem2 = amount.getText();
					a1 = a * Float.parseFloat(tem2.equals("") ? "0" : tem2);
					String b = String.valueOf(a);
					String b1 = String.valueOf(a1);
					taxprice.setText(b);
					total.setText(b1);

				}
			});
			gd_id1.setBounds(132, 375, 80, 21);
			panel_1.add(gd_id1);

			final JComboBox gd_id2 = new JComboBox();
			gd_id2.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent e) {
					if (gd_id2.getSelectedItem() == ""
							|| gd_id2.getSelectedItem() == null) {
						return;
					}

					try {
						String sql = "select * from PutInStorageDetail where PutInStorageDetail.pi_id='"
								+ pi_id.getText()
								+ "' and  PutInStorageDetail.gd_id='"
								+ gd_id2.getSelectedItem() + "'";
						Connection conn = connect.getConnection();
						Statement stat = conn.createStatement();
						int r5 = 0;
						ResultSet rs = stat.executeQuery(sql);
						while (rs.next()) { // ����ȡ�����
							// JOptionPane.showMessageDialog(null, "+++++++"); //����
							r5 = rs.getInt(2);
							gd_id1.addItem(r5);
							gd_name1.setText("");
							gd_type1.setText("");
							gd_unit1.setText("");
							amount.setText("");
							unitprice.setText("");
							tax.setText("");
							taxprice.setText("");
							total.setText("");
							gd_name1.setText(rs.getString(3));
							gd_type1.setText(rs.getString(4));
							gd_unit1.setText(rs.getString(5));
							amount.setText(rs.getString(6));
							unitprice.setText(rs.getString(7));
							tax.setText(rs.getString(8));
							taxprice.setText(rs.getString(9));
							total.setText(rs.getString(10));
						}

						stat.close();
						conn.close();
					} catch (SQLException sqlex) {
						sqlex.printStackTrace();
					} catch (IOException e1) {
						e1.printStackTrace();
					}

				}
			});
			gd_id2.setBounds(132, 375, 80, 21);
			panel_1.add(gd_id2);
			gd_id2.setVisible(false);

			gd_name1 = new JTextField();
			gd_name1.setEditable(false);
			gd_name1.setBounds(220, 375, 66, 21);
			panel_1.add(gd_name1);
			gd_name1.setColumns(10);

			gd_type1 = new JTextField();
			gd_type1.setEditable(false);
			gd_type1.setColumns(10);
			gd_type1.setBounds(290, 375, 66, 21);
			panel_1.add(gd_type1);

			gd_unit1 = new JTextField();
			gd_unit1.setEditable(false);
			gd_unit1.setColumns(10);
			gd_unit1.setBounds(360, 375, 66, 21);
			panel_1.add(gd_unit1);

			amount = new JTextField();
			amount.addCaretListener(new CaretListener() {
				public void caretUpdate(CaretEvent e) {

					if (isNotNumber(amount.getText())) {
						JOptionPane.showMessageDialog(panel_1, "����д���֣�");
						amount.setText("");
						amount.requestFocus();
					}

					float a, a1;
					String tem = unitprice.getText();

					a = 1
							+ Float.parseFloat(tem.equals("") ? "0" : tem)
							* (Float.parseFloat(tax.getText().equals("") ? "17"
									: tax.getText())) / 100;

					String tem2 = amount.getText();
					// System.out.println(tem2+"----------------------");
					// JOptionPane.showMessageDialog(null, tem2);
					// //����+++++++++++++++++++++++
					a1 = a * Float.parseFloat(tem2.equals("") ? "0" : tem2);
					String b = String.valueOf(a);
					String b1 = String.valueOf(a1);
					taxprice.setText(b);
					total.setText(b1);

				}
			});

			amount.setColumns(10);
			amount.setBounds(430, 375, 66, 21);
			panel_1.add(amount);

			unitprice = new JTextField();
			unitprice.setEditable(false);
			unitprice.setColumns(10);
			unitprice.setBounds(500, 375, 66, 21);
			panel_1.add(unitprice);

			tax = new JTextField();
			tax.addCaretListener(new CaretListener() {
				public void caretUpdate(CaretEvent arg0) {

					// JOptionPane.showMessageDialog(null, "+++++++"); //
					// ����+++++++++++++++++++++++

					if (isNotNumber(tax.getText())) {
						JOptionPane.showMessageDialog(null, "����д���֣�");
						tax.setText("");
						tax.requestFocus();
					}

					float a, a1;
					String tem = unitprice.getText();
					a = 1
							+ Float.parseFloat(tem.equals("") ? "0" : tem)
							* (Float.parseFloat(tax.getText().equals("") ? "17"
									: tax.getText())) / 100;
					String tem2 = amount.getText();
					// JOptionPane.showMessageDialog(null, tem2); //
					// ����+++++++++++++++++++++++
					a1 = a * Float.parseFloat(tem2.equals("") ? "0" : tem2);
					String b = String.valueOf(a);
					String b1 = String.valueOf(a1);
					taxprice.setText(b);
					total.setText(b1);

				}
			});

			tax.setColumns(10);
			tax.setBounds(570, 375, 66, 21);
			panel_1.add(tax);

			taxprice = new JTextField();
			taxprice.setEditable(false);
			taxprice.setColumns(10);
			taxprice.setBounds(640, 375, 66, 21);
			panel_1.add(taxprice);

			total = new JTextField();
			total.setEditable(false);
			total.setColumns(10);
			total.setBounds(710, 375, 66, 21);
			panel_1.add(total);

			JLabel label_55 = new JLabel("\u65B0\u589E");
			label_55.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					pi_time.setText("");
					department.removeAllItems();
					yewuyuan.removeAllItems();
					supplier.removeAllItems();
					warehouse.removeAllItems();
					memo.setText("");
					zhidanren.setText(Constant.Name);
					zd_time.setText("");
					shenheren.setText("");
					sh_time.setText("");
					label_62.setVisible(false);
					try {
						int r = 0;
						String sql = "SELECT MAX(pi_id) FROM PutInStorage";
						Connection conn = connect.getConnection();
						Statement stat = conn.createStatement();
						ResultSet rs = stat.executeQuery(sql);

						while (rs.next()) { // ����ȡ�����
							r = rs.getInt(1) + 1;
							pi_id.setText(String.valueOf(r));

						}

						String r1 = "", r2 = "", r3 = "", r4 = "";
						String sql1 = "select * from  Department where de_type='�ִ�'";
						String sql3 = "select * from Supplier";
						String sql4 = "select * from Warehouse";
						ResultSet rs1 = stat.executeQuery(sql1);
						while (rs1.next()) { // ����ȡ�����
							r1 = rs1.getString(2);
							department.addItem(r1);
						}

						ResultSet rs3 = stat.executeQuery(sql3);
						while (rs3.next()) { // ����ȡ�����
							r3 = rs3.getString(2);
							supplier.addItem(r3);
						}

						ResultSet rs4 = stat.executeQuery(sql4);
						while (rs4.next()) { // ����ȡ�����
							r4 = rs4.getString(2);
							warehouse.addItem(r4);
						}

						Table.DrawTable(pi_id.getText(), panel_1, table);

						stat.close();
						conn.close();
					} catch (SQLException sqlex) {
						sqlex.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
					}

				}
			});
			label_55.setFont(new Font("΢���ź�", Font.PLAIN, 15));
			label_55.setHorizontalAlignment(SwingConstants.CENTER);
			label_55.setForeground(new Color(0, 0, 205));
			label_55.setBounds(410, 0, 60, 30);
			panel_1.add(label_55);

			JLabel label_56 = new JLabel("\u4FDD\u5B58");
			label_56.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(PutInStorage.getState(pi_id.getText())==1){JOptionPane.showMessageDialog(panel_1, "�Բ��𣬸���ⵥ�Ѿ���ˣ������޸ģ�");return;}
					if (pi_time.getText().trim().length() == 0
							|| zhidanren.getText().trim().length() == 0
							|| zd_time.getText().trim().length() == 0) {
						JOptionPane.showMessageDialog(panel_1, "��������Ϣ��");
						// cu_name.requestFocus(true);
						return;
					}

					try {

						Connection conn = connect.getConnection();
						Statement stat = conn.createStatement();

						String sql = "SELECT * FROM PutInStorage where pi_id= '"
								+ pi_id.getText() + "'";
						String sql_1 = "insert into PutInStorage(pi_id,pi_time,department,yewuyuan,supplier,warehouse,memo,zhidanren,zd_time,shenheren,sh_time,sh_state) values('"
								+ pi_id.getText()
								+ "','"
								+ pi_time.getText()
								+ "','"
								+ department.getSelectedItem()
								+ "','"
								+ yewuyuan.getSelectedItem()
								+ "','"
								+ supplier.getSelectedItem()
								+ "','"
								+ warehouse.getSelectedItem()
								+ "','"
								+ memo.getText()
								+ "','"
								+ zhidanren.getText()
								+ "','"
								+ zd_time.getText()
								+ "','"
								+ shenheren.getText()
								+ "','"
								+ sh_time.getText()
								+ "','"
								+ 0
								+ "')";

						String sql_2 = "update PutInStorage set pi_time='"
								+ pi_time.getText() + "',department='"
								+ department.getSelectedItem() + "',yewuyuan='"
								+ yewuyuan.getSelectedItem() + "',supplier='"
								+ supplier.getSelectedItem() + "',warehouse='"
								+ warehouse.getSelectedItem() + "',memo='"
								+ memo.getText() + "',zhidanren='"
								+ zhidanren.getText() + "',zd_time='"
								+ zd_time.getText() + "',shenheren='"
								+ shenheren.getText() + "',sh_time='"
								+ sh_time.getText() + "',sh_state='"+0+"' where pi_id='"
								+ pi_id.getText() + "' ";
						ResultSet rs = stat.executeQuery(sql);

						if (rs.next()) {

							int rs_2 = stat.executeUpdate(sql_2);
							if (rs_2 > 0) {
								if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
								else{label_62.setText("δ���");}
								label_62.setVisible(true);
								Table.DrawTable(pi_id.getText(), panel_1, table);
								JOptionPane.showMessageDialog(panel_1, " ���³ɹ���");
							
							}

						} else {

							int rs_1 = stat.executeUpdate(sql_1);
							if (rs_1 > 0) {
								if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
								else{label_62.setText("δ���");}
								label_62.setVisible(true);
								Table.DrawTable(pi_id.getText(), panel_1, table);
								JOptionPane.showMessageDialog(panel_1, " ��ӳɹ���");
								
							}
						}

						stat.close();
						conn.close();
					} catch (SQLException sqlex) {
						sqlex.printStackTrace();
					} catch (IOException e1) {
						e1.printStackTrace();
					}

				}
			});
			label_56.setFont(new Font("΢���ź�", Font.PLAIN, 15));
			label_56.setHorizontalAlignment(SwingConstants.CENTER);
			label_56.setForeground(new Color(0, 0, 205));
			label_56.setBounds(484, 0, 60, 30);
			panel_1.add(label_56);

			department.addItemListener(new ItemListener() {
				@SuppressWarnings("unchecked")
				public void itemStateChanged(ItemEvent arg0) {
					yewuyuan.removeAllItems();
					try {

						String r = "";

						String sql2 = "select ep_name from Employee where Employee.ep_department='"
								+ department.getSelectedItem() + "'";

						Connection conn = connect.getConnection();
						Statement stat = conn.createStatement();

						ResultSet rs = stat.executeQuery(sql2);
						while (rs.next()) { // ����ȡ�����
							r = rs.getString(1);
							yewuyuan.addItem(r);
						}

						stat.close();
						conn.close();
					} catch (SQLException sqlex) {
						sqlex.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
					}

				}
			});

			final JLabel label_59 = new JLabel("\u5BA1\u6838");
			label_59.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					
					Integer a=PutInStorage.getState(pi_id.getText());
					if(a==1){JOptionPane.showMessageDialog(panel_1, "����ⵥ�Ѿ���ˣ�");return;}
					if(a==2){JOptionPane.showMessageDialog(panel_1, "����ⵥδ���棬���ȱ��棡");return;}
					else{
						try {

							shenheren.setText(Constant.getName());
//							System.out.println(sh_time.getText()+"+++++");
							if(sh_time.getText().equals("1900-01-01")||sh_time.getText().equals("")){sh_time.setText(getCurrentDate());}
							String sql = "update PutInStorage set shenheren='"
									+ shenheren.getText() + "',sh_time='"
									+ sh_time.getText() + "',sh_state="+1+" where pi_id='"
									+ pi_id.getText() + "' ";
							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							int rs = stat.executeUpdate(sql);
							if(rs>0) { // ����ȡ�����
								if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
								else{label_62.setText("δ���");}
								label_62.setVisible(true);
								JOptionPane.showMessageDialog(panel_1, "��˳ɹ���");
							}

							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
						
						
					}
					
					
					
				}
			});
			label_59.setHorizontalAlignment(SwingConstants.CENTER);
			label_59.setForeground(new Color(0, 0, 205));
			label_59.setFont(new Font("΢���ź�", Font.PLAIN, 15));
			label_59.setBounds(630, 0, 60, 30);
			panel_1.add(label_59);
			
			final JLabel label_61 = new JLabel("\u53D6\u6D88\u5BA1\u6838");
			label_61.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
						
					Integer a=PutInStorage.getState(pi_id.getText());
					if(a==0){JOptionPane.showMessageDialog(panel_1, "����ⵥδ��ˣ�");return;}
					if(a==2){JOptionPane.showMessageDialog(panel_1, "�����δ���棬���ȱ��棡");return;}
						try {

							
//							System.out.println(sh_time.getText()+"+++++");
							if(sh_time.getText().equals("1900-01-01")||sh_time.getText().equals("")){sh_time.setText(getCurrentDate());}
							String sql = "update PutInStorage set shenheren='"
									+ "" + "',sh_time='"
									+ "" + "',sh_state='"
									+0+"' where pi_id='"
									+ pi_id.getText() + "' ";
							System.out.println(sql);
							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							int rs = stat.executeUpdate(sql);
							if(rs>0) { // ����ȡ�����
								shenheren.setText("");
								sh_time.setText("");
								if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
								else{label_62.setText("δ���");}
								label_62.setVisible(true);
								JOptionPane.showMessageDialog(panel_1, "ȡ����˳ɹ���");
							}

							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();	
					}
						
				}
			});
			label_61.setHorizontalAlignment(SwingConstants.CENTER);
			label_61.setForeground(new Color(0, 0, 205));
			label_61.setFont(new Font("΢���ź�", Font.PLAIN, 15));
			label_61.setBounds(695, 0, 60, 30);
			panel_1.add(label_61);
			department.setBounds(672, 130, 90, 21);
			panel_1.add(department);

			panel_1.addComponentListener(new ComponentAdapter() {

				@SuppressWarnings("unchecked")
				@Override
				public void componentShown(ComponentEvent arg0) {

					pi_id.setText("");
					pi_time.setText("");
					department.removeAllItems();
					yewuyuan.removeAllItems();
					supplier.removeAllItems();
					warehouse.removeAllItems();
					memo.setText("");
					zhidanren.setText("");
					zd_time.setText("");
					shenheren.setText("");
					sh_time.setText("");
					gd_id1.removeAllItems();
					gd_name1.setText("");
					gd_type1.setText("");
					gd_unit1.setText("");
					amount.setText("1");
					unitprice.setText("");
					tax.setText("17");

					taxprice.setText("");
					total.setText("");

					try {
						int r0 = 0;
						int r5 = 0;

						String sql0 = "select top 1 * from PutInStorage order by pi_id desc";

						String sql5 = "select gd_id from Good";

						Connection conn = connect.getConnection();
						Statement stat = conn.createStatement();

						ResultSet rs0 = stat.executeQuery(sql0);
						// System.out.print(rs0);
						while (rs0.next()) { // ����ȡ�����

							r0 = rs0.getInt(1);
							pi_id.setText(String.valueOf(r0));
							String a3 = rs0.getDate(2).toString();
							pi_time.setText((a3 == null || a3 == "") ? "" : a3);
							department.addItem(rs0.getString(3));
							yewuyuan.removeAllItems();
							yewuyuan.addItem(rs0.getString(4));
							supplier.addItem(rs0.getString(5));
							warehouse.addItem(rs0.getString(6));
							memo.setText(rs0.getString(7));
							zhidanren.setText(rs0.getString(8));
							String a = rs0.getDate(9).toString();
							zd_time.setText(a);

							String a1 = rs0.getString(10);

							shenheren.setText((a1 == null || a1 == "") ? "" : a1);

							Date a2 = rs0.getDate(11);
							sh_time.setText((a2 == null) ? "" : a2.toString());

						}

						ResultSet rs5 = stat.executeQuery(sql5);
						while (rs5.next()) { // ����ȡ�����
							r5 = rs5.getInt(1);
							gd_id1.addItem(r5);
						}

						// JOptionPane.showMessageDialog(null, pi_id.getText());
						// //����

						stat.close();
						conn.close();
					} catch (SQLException sqlex) {
						sqlex.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
					}
					if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
					else{label_62.setText("δ���");}
					Table.DrawTable(pi_id.getText(), panel_1, table);
					if(Constant.getLevel().equals("1")){label_59.setVisible(false);label_61.setVisible(false);}
					
				}

			});
			tabbedPane.addTab("\u5165\u5E93\u5355", null, panel_1, null);
			panel_1.setLayout(null);

			final JComboBox option = new JComboBox();
			option.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent arg0) {

					if (option.getSelectedIndex() == 0) {
						gd_id2.removeAllItems();
						gd_id2.setVisible(false);
						gd_id1.removeAllItems();
						gd_id1.setVisible(true);
						gd_name1.setText("");
						gd_type1.setText("");
						gd_unit1.setText("");
						amount.setText("1");
						unitprice.setText("");
						tax.setText("17");
						taxprice.setText("");
						total.setText("");
						try {

							int r5 = 0;
							String sql5 = "select gd_id from Good";
							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							ResultSet rs5 = stat.executeQuery(sql5);
							while (rs5.next()) { // ����ȡ�����
								r5 = rs5.getInt(1);
								gd_id1.addItem(r5);
							}

							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}

					} else if (option.getSelectedIndex() == 1) {
						gd_id1.removeAllItems();
						gd_id1.setVisible(false);
						gd_id2.setVisible(true);
						gd_id2.removeAllItems();
						gd_name1.setText("");
						gd_type1.setText("");
						gd_unit1.setText("");
						amount.setText("");
						unitprice.setText("");
						tax.setText("");
						taxprice.setText("");
						total.setText("");
						try {

							int r5 = 0;
							String sql5 = "select * from PutInStorageDetail where PutInStorageDetail.pi_id='"
									+ pi_id.getText() + "'";
							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							ResultSet rs5 = stat.executeQuery(sql5);
							while (rs5.next()) { // ����ȡ�����
								r5 = rs5.getInt(2);
								gd_id2.addItem(r5);
							}

							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
					} else if (option.getSelectedIndex() == 2) {
						gd_id1.removeAllItems();
						gd_id1.setVisible(false);
						gd_id2.setVisible(true);
						gd_id2.removeAllItems();
						gd_name1.setText("");
						gd_type1.setText("");
						gd_unit1.setText("");
						amount.setText("");
						unitprice.setText("");
						tax.setText("");
						taxprice.setText("");
						total.setText("");
						try {

							int r5 = 0;
							String sql5 = "select * from PutInStorageDetail where PutInStorageDetail.pi_id='"
									+ pi_id.getText() + "'";
							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							ResultSet rs5 = stat.executeQuery(sql5);
							while (rs5.next()) { // ����ȡ�����
								r5 = rs5.getInt(2);
								gd_id2.addItem(r5);
							}

							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}

				}
			});
			option.addItem("添加");
			option.addItem("修改");
			option.addItem("删除");
			option.setToolTipText("");
			option.setBounds(786, 375, 60, 21);
			panel_1.add(option);

			JLabel label_58 = new JLabel("\u64CD\u4F5C");
			label_58.setHorizontalAlignment(SwingConstants.CENTER);
			label_58.setBounds(792, 350, 54, 15);
			panel_1.add(label_58);

			JButton button = new JButton("\u786E\u5B9A");
			button.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					Integer a=PutInStorage.getState(pi_id.getText());
					if(a==1){JOptionPane.showMessageDialog(panel_1, "�Բ��𣬸���ⵥ�Ѿ���ˣ������޸ģ�");return;}
					
					if (option.getSelectedIndex() == 0) {
						if (amount.getText().trim().length() == 0
								|| tax.getText().trim().length() == 0) {
							JOptionPane.showMessageDialog(panel_1, "��������Ϣ��");
							// amount.requestFocus(true);
							return;
						}

						try {

							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							String sql = "SELECT * FROM PutInStorage where pi_id= '"
									+ pi_id.getText() + "'";
							
							String sql_1 = "insert into PutInStorage(pi_id,pi_time,department,yewuyuan,supplier,warehouse,memo,zhidanren,zd_time,shenheren,sh_time,sh_state) values('"
									+ pi_id.getText()
									+ "','"
									+ pi_time.getText()
									+ "','"
									+ department.getSelectedItem()
									+ "','"
									+ yewuyuan.getSelectedItem()
									+ "','"
									+ supplier.getSelectedItem()
									+ "','"
									+ warehouse.getSelectedItem()
									+ "','"
									+ memo.getText()
									+ "','"
									+ zhidanren.getText()
									+ "','"
									+ zd_time.getText()
									+ "','"
									+ shenheren.getText()
									+ "','"
									+ sh_time.getText()
									+ "','"
									+ 0
									+ "')";
							String sql_3 = "SELECT * FROM PutInStorageDetail where PutInStorageDetail.pi_id= '"
									+ pi_id.getText()
									+ "' and PutInStorageDetail.gd_id='"
									+ gd_id1.getSelectedItem() + "'";// �ж��Ƿ��Ѿ����ڸ���Ʒ
							// ������Ʒ
							String sql_4 = "insert into PutInStorageDetail(pi_id,gd_id,gd_name,gd_type,gd_unit,amount,unitprice,tax,taxprice,total) values('"
									+ pi_id.getText()
									+ "','"
									+ gd_id1.getSelectedItem()
									+ "','"
									+ gd_name1.getText()
									+ "','"
									+ gd_type1.getText()
									+ "','"
									+ gd_unit1.getText()
									+ "','"
									+ amount.getText()
									+ "','"
									+ unitprice.getText()
									+ "','"
									+ tax.getText()
									+ "','"
									+ taxprice.getText()
									+ "','" + total.getText() + "')";
							
							ResultSet rs_3 = stat.executeQuery(sql_3);

							if (rs_3.next()) {
								JOptionPane.showMessageDialog(panel_1,
										" ����ⵥ���Ѿ����ڸ���Ʒ�������Ҫ���޸ģ�������޸Ĳ�����");
								return;

							}
							
							ResultSet rs= stat.executeQuery(sql);
							if (rs.next()) {
								int rs_4 = stat.executeUpdate(sql_4);
								if (rs_4 > 0) {
									if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
									else{label_62.setText("δ���");}
									label_62.setVisible(true);
									Table.DrawTable(pi_id.getText(), panel_1, table);
									
									JOptionPane.showMessageDialog(panel_1, " ��ӳɹ���");

								}
								
							}
							else{
								int rs_1=stat.executeUpdate(sql_1);
								
								int rs_4 = stat.executeUpdate(sql_4);
								if (rs_1>0 && rs_4 > 0) {
									if(PutInStorage.getState(pi_id.getText())==1){label_62.setText("�����");}
									else{label_62.setText("δ���");}
									label_62.setVisible(true);
									Table.DrawTable(pi_id.getText(), panel_1, table);
									
									JOptionPane.showMessageDialog(panel_1, " ��ӳɹ���");

									

								}
							}
							

							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e1) {
							e1.printStackTrace();
						}

					}

					if (option.getSelectedIndex() == 1) {
						if (amount.getText().trim().length() == 0
								|| tax.getText().trim().length() == 0) {
							JOptionPane.showMessageDialog(panel_1, "��������Ϣ��");
							// amount.requestFocus(true);
							return;
						}

						try {

							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							String sql_3 = "SELECT * FROM PutInStorageDetail where PutInStorageDetail.pi_id= '"
									+ pi_id.getText()
									+ "' and PutInStorageDetail.gd_id='"
									+ gd_id2.getSelectedItem() + "'";// �ж��Ƿ��Ѿ����ڸ���Ʒ
							// ������Ʒ

							String sql_5 = "update PutInStorageDetail set gd_name='"
									+ gd_name1.getText()
									+ "',gd_type='"
									+ gd_type1.getText()
									+ "',gd_unit='"
									+ gd_unit1.getText()
									+ "',amount='"
									+ amount.getText()
									+ "',unitprice='"
									+ unitprice.getText()
									+ "',tax='"
									+ tax.getText()
									+ "',taxprice='"
									+ taxprice.getText()
									+ "',total='"
									+ total.getText()
									+ "' where PutInStorageDetail.pi_id='"
									+ pi_id.getText()
									+ "' and PutInStorageDetail.gd_id='"
									+ gd_id2.getSelectedItem() + "' ";

							ResultSet rs_3 = stat.executeQuery(sql_3);

							if (rs_3.next()) {

								int rs_5 = stat.executeUpdate(sql_5);
								if (rs_5 > 0) {
									Table.DrawTable(pi_id.getText(), panel_1, table);
									JOptionPane
											.showMessageDialog(panel_1, " ���³ɹ���");
									
								}

							} else {
								JOptionPane.showMessageDialog(panel_1,
										" ����ⵥ����Ʒ�����ڣ�");
							}

							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e1) {
							e1.printStackTrace();
						}

					}

					if (option.getSelectedIndex() == 2) {
						try {

							Connection conn = connect.getConnection();
							Statement stat = conn.createStatement();
							String sql_3 = "SELECT * FROM PutInStorageDetail where PutInStorageDetail.pi_id= '"
									+ pi_id.getText()
									+ "' and PutInStorageDetail.gd_id='"
									+ gd_id2.getSelectedItem() + "'";// �ж��Ƿ��Ѿ����ڸ���Ʒ
							// ������Ʒ

							String sql_5 = "delete from PutInStorageDetail where PutInStorageDetail.pi_id='"
									+ pi_id.getText()
									+ "' and PutInStorageDetail.gd_id='"
									+ gd_id2.getSelectedItem() + "' ";

							ResultSet rs_3 = stat.executeQuery(sql_3);

							if (rs_3.next()) {

								int rs_5 = stat.executeUpdate(sql_5);
								if (rs_5 > 0) {
									Table.DrawTable(pi_id.getText(), panel_1, table);
//									JOptionPane.showMessageDialog(panel_1, " ɾ��ɹ���");
								}

							} else {

								JOptionPane.showMessageDialog(panel_1, " ����Ʒ�����ڣ�");
							}
							stat.close();
							conn.close();
						} catch (SQLException sqlex) {
							sqlex.printStackTrace();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					}

				}
			});
			button.setBounds(856, 373, 60, 25);
			panel_1.add(button);

			ScrollPane scrollPane = new ScrollPane();
			scrollPane.setBounds(130, 402, 716, 100);
			panel_1.add(scrollPane);
			
			
			
			
		}
		
		public static boolean isNotNumber(String str) {
			boolean a = true;
			if (str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$")) {
				a = false;
			}
			return a;
		}
		
		public static String getCurrentDate(){
			 int year=0;
		        int month=0;
		        int day=0;
		        Calendar c=Calendar.getInstance();//���ϵͳ��ǰ����
		        year=c.get(Calendar.YEAR);
		        month=c.get(Calendar.MONTH)+1;//ϵͳ���ڴ�0��ʼ����
		        day=c.get(Calendar.DAY_OF_MONTH);
		        String date=String.valueOf(year)+"/"+String.valueOf(month)+"/"+String.valueOf(day);
		        return date;
		}

	
}
